// adminSessionBeanClient.java
// mini Client for accessing bean adminSessionBean

package adminSession;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

/**
 * @author Mamadou TOURE
 * The adminSessionClient class allow to test the adminSession implementation
 */
public class adminSessionClient 
{

    static Context ctx = null; 
    static adminSessionHome home = null;

    public static void main(String[] arg) 
    {
    	// Get InitialContext
    	try 
    	{
    		ctx = getInitialContext();
    	}
    	catch (NamingException e) 
    	{
    		e.printStackTrace();
    		System.exit(2);
    	}

    	// Lookup bean home 
    	String bName = "MyAdminSession";
    	try 
    	{
    		home = (adminSessionHome) PortableRemoteObject.narrow(ctx.lookup(bName), adminSessionHome.class);
    		adminSession bean = home.create(0);
//            bean.addStudent("test","test","test","xxx","test@t.est");
//            bean.addStudent("test2","test2","test","xxx","test2@t.est");
//            bean.removeStudent(102);
    	} 
    	catch(Exception e) 
    	{
    		//e.printStackTrace();
    		System.out.println("error : adminSessionClient" +e);
    		System.exit(2);
    	}
    }
    
    /**
	 * Using a Properties object will work on JDK 1.1.x and Java2
	 * clients
	 */
	static private Context getInitialContext() throws NamingException 
	{
      String url = "rmi://localhost:1099";
      
	  try 
	  {
		// Get an InitialContext
		Properties h = new Properties();
		h.put(Context.INITIAL_CONTEXT_FACTORY,"org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
		h.put(Context.PROVIDER_URL, url);
		return new InitialContext(h);
	  } 
	  catch (NamingException ne)
	  {
	  	ne.printStackTrace();
		throw ne;
	  }
	}
}
